/***扑克房间数据类
 * 
 */
var _ = require('../../FrameWork/we_underscore');
var EnumPkRoom = require('./../Enum/EnumPkRoom');
module.exports = cc.Class({
    ctor() {
        this.doInit();
    },
    doInit() {
        this.selfSeatIdx = -1; //我自己服务器的座位id
        this.currSeatIdx = -1; //当前可操作的玩家
        this.seatObjList = []; //座位信息
        this.lastOutCardInfo = null; //上个出牌玩家的信息
        this.roomState = EnumPkRoom.WAITING; //房间状态
        this.bankerSeatIdx = -1; //庄家座位id
    },
    /**是否为重新出牌 比如没人接牌了,其中也包含第一次出牌*/
    isResetOutCard() {
        if (null == this.lastOutCardInfo) {
            return true;
        }
        return this.lastOutCardInfo.seatIdx == this.currSeatIdx;
    },
    /***设置最后出牌信息 */
    setLastOutCardInfo(_lastOutCardInfo) {
        this.lastOutCardInfo = _lastOutCardInfo;
    },
    /***最后出牌信息 */
    getLastOutCardInfo() {
        return this.lastOutCardInfo;
    },
    /***刷新房间状态 */
    refreshRoomState(_roomState) {
        this.roomState = _roomState;
    },
    /***获得房间状态 */
    getRoomState() {
        return this.roomState;
    },
    /***设置庄家座位id */
    setBankerSeatIdx(_seatIdx) {
        this.bankerSeatIdx = _seatIdx;
    },
    /***获得庄家座位id' */
    getBankerSeatIdx() {
        return this.bankerSeatIdx;
    },
    /***起手发牌 */
    sendFristCard() {
        //子类自己实现
    },

    /***加入一个 */
    joinSeatByInfo(_seatInfo) {

    },

    /***加入一个 */
    joinSeat(_seatObj) {
        this.seatObjList.push(_seatObj);
    },

    /***最大座位数 */
    getMaxSeatCnt() {
        return 3;
    },

    /***获得当前出牌的玩家id */
    getCurrOutSeatIdx() {
        return this.currSeatIdx;
    },
    /***是否为机器人 */
    getIsRobot(_seatIdx) {

    },
    /**==========================自己相关的方法============================**/
    /***获得当前座位数量 */
    getSeatNumber() {
        return _.size(this.seatObjList);
    },
    /**是否为自己出牌 */
    isSelfOutCard() {
        return this.selfSeatIdx == this.currSeatIdx;
    },
    /***设置自己的座位id */
    setSelfSeatIdx(_seatIdx) {
        this.selfSeatIdx = _seatIdx;
    },
    /***我自己服务器的座位id */
    getSelfSeatIdx() {
        return this.selfSeatIdx;
    },
    /***自己的座位信息 */
    getSelfSeat() {
        return this.seatObjList[this.selfSeatIdx];
    },
    getSeatByIdx(_seatIdx) {
        return this.seatObjList[_seatIdx];
    },
    /**设置当前可出牌的玩家_seatIdx*/
    setCurrOutSeatIdx(_seatIdx) {
        this.currSeatIdx = _seatIdx;
    },

    /***出牌动作
     * _outCardInfo:{seatIdx:1,type:1,cardIds:[]}
     */
    outCardAct(_outCardInfo) {
        this.setLastOutCardInfo(_outCardInfo);
        var seatIdx = _outCardInfo.seatIdx;
        var cardLeftCnt = this.seatObjList[seatIdx].outCardAct(_outCardInfo);
        if (cardLeftCnt > 0) {
            this.switchNextSeatIdx(seatIdx);
        }
        return cardLeftCnt;
    },
    /***要不起 
     * info:{
     *   seatIdx:1
     * }
     */
    noOut(info) {
        var seatIdx = info.seatIdx;
        return this.switchNextSeatIdx(seatIdx);
    },


    /***切换出牌权*/
    switchNextSeatIdx(_seatIdx) {
        /***切换下个出牌 */
        var nextSeatIdx = (_seatIdx < this.getMaxSeatCnt() - 1) ? (++_seatIdx) : 0
        this.setCurrOutSeatIdx(nextSeatIdx);
        return nextSeatIdx;
    },

    /***通过座位获得性别 */
    getSex(_seatIdx) {
        return this.seatObjList[_seatIdx].getSex();
    },
    each(cb) {
        _.each(this.seatObjList, function(_seatObj) {
            cb(_seatObj);
        });
    },
    /**==========================子类自己实现============================**/
    /**换桌 */
    doChangDesk() {
        //子类自己实现
    },
    /**继续 */
    doContinue() {
        //子类自己实现
    },
    /** 
     * @param {结算数据} _endInfo 
     */
    doGameEnd(_endInfo) {
        //子类自己实现
    },
});